package com.haoliang.spring.component.java.registrar;

import com.haoliang.spring.component.java.bean.RainBow;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
import org.springframework.core.type.AnnotationMetadata;

/**
 * @Author zhaohaoliang
 * @Date 创建于 下午4:52 2019/3/10
 * @Description 请输入类的描述信息
 */
public class CustomBeanRegistrar implements ImportBeanDefinitionRegistrar {
    /**
     * @param importingClassMetadata 注解类的全部类信息
     * @param registry Bean注册类 添加Bean到容器中registry.registerBeanDefinition()
     */
    public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
        boolean redModel = registry.containsBeanDefinition("com.haoliang.spring.component.java.model.RedModel");
        boolean greenModel = registry.containsBeanDefinition("com.haoliang.spring.component.java.model.GreenModel");
        boolean blueModel = registry.containsBeanDefinition("com.haoliang.spring.component.java.model.BlueModel");
        if (redModel && greenModel && blueModel) {
            RootBeanDefinition beanDefinition = new RootBeanDefinition(RainBow.class);
            registry.registerBeanDefinition("rainBow", beanDefinition);
        }
    }
}
